package com.xiaomaoguai.redis.sub2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;

/**
 * 推送类型
 *
 * @ FileName: PushMsgEnum.java
 * @ Author: WeiHui-Z
 * @ Date: 2017/4/21 10:28
 * @ Version: v1.0.0
 */
public enum PushMsgEnum {

    PUSH_NOTICE("1", "通知"),

    PUSH_WARING("2", "超时预警"),

    PUSH_WARING_GROUP("3", "超时预警组"),

    PUSH_TASK("4", "分配任务"),

    PUSH_CANCEL_CONTRACT("5", "销售取消"),

    PUSH_MANAGER_REJECT_CONTRACT("6", "销售经理否决");

    private static final List<String> PUSH_TYPES = Collections.synchronizedList(new ArrayList<String>());

    static {
        for (PushMsgEnum msgEnum : EnumSet.allOf(PushMsgEnum.class)) {
            PUSH_TYPES.add(msgEnum.name());
        }
    }

    /**
     * 类型
     */
    private String type;

    /**
     * 描述
     */
    private String desc;

    PushMsgEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static String getTypeByName(String name) {
        return PushMsgEnum.valueOf(name).getType();
    }

    public static List<String> getPushTypes() {
        return PUSH_TYPES;
    }

    public static String getRandomPushType() {
        final int size = PUSH_TYPES.size();
        final Random random = new Random();
        final int index = random.nextInt(size);
        return PUSH_TYPES.get(index);
    }

    @Override
    public String toString() {
        return "PushMsgEnum{" +
                "type='" + type + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}
